package com.woniuxy.service.location.impl;

import com.woniuxy.entity.County;
import com.woniuxy.mapper.CountyMapper;
import com.woniuxy.service.location.CountyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 马踏东京赏樱花
 */
@Service
public class CountyServiceImpl implements CountyService {
    @Autowired
    private CountyMapper countyMapper;

    @Override
    public List<County> findAllCounty(Integer cityId) {
        return countyMapper.findAllCounty(cityId);
    }

    @Override
    public int addOne(String str) {
        County county = new County();
        county.setCountyName(str);
        int insert = countyMapper.insert(county);
        if (insert == 1) {
            return insert;
        }
        throw new RuntimeException("添加失败");
    }

    @Override
    public int deleteOne(String str) {
        if (str == null) {
            throw new RuntimeException("数据获取失败");
        }
        County county = new County();
        county.setCountyId(Integer.valueOf(str));
        return countyMapper.deleteByPrimaryKey(county.getCountyId());
    }

    @Override
    public County findOne(String str) {
        if (str == null) {
            throw new RuntimeException("数据获取失败");
        }
        County county = new County();
        county.setCountyId(Integer.valueOf(str));
        return countyMapper.selectByPrimaryKey(county.getCountyId());
    }

    @Override
    public List<County> findAll() {
        return countyMapper.selectByExample(null);
    }

    @Override
    public County updateOne(County county) {
        int i = countyMapper.updateByPrimaryKey(county);
        if (i > 0) {
            return county;
        }
        throw new RuntimeException("修改失败");
    }
}
